#!/bin/python

#
#Xithyl, Test Driven Development for C
#Copyright (C) 2012  Stepan Henek
#
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

from xithyl import logger
from xithyl.Ctypes.basic import *
from xithyl.Ctypes import libc
from xithyl.conditions import basic
from xithyl import actions

logger.addLogger(__name__)

def functional1():
    """
    Create four strings. Compare one another
    Compare strings.
    """

    result = True

    logger.log("Functional 1", __name__)


    str1 = c_char_p("String")
    logger.log("Init string 1 \"%s\"" % str1.value, __name__)
    str2 = c_char_p("Strin")
    logger.log("Init string 2 \"%s\"" % str2.value, __name__)
    str3 = c_char_p("String")
    logger.log("Init string 3 \"%s\"" % str3.value, __name__)
    str4 = c_char_p("String1")
    logger.log("Init string 4 \"%s\"" % str4.value, __name__)

    # Test assignment
    result &= basic.stringEqual(str1.value, "String", __name__, True)
    result &= basic.stringEqual(str2.value, "Strin", __name__, True)
    result &= basic.stringEqual(str3.value, "String", __name__, True)
    result &= basic.stringEqual(str4.value, "String1", __name__, True)


    # Call memcmp
    res = libc.string.strcmp(str1.value, str1.value)
    result &= basic.numbersEquals(res, 0, __name__, True)
    res = libc.string.strcmp(str1.value, str2.value)
    result &= basic.numbersHigher(res, 0, __name__, True)
    res = libc.string.strcmp(str1.value, str3.value)
    result &= basic.numbersEquals(res, 0, __name__, True)
    res = libc.string.strcmp(str1.value, str4.value)
    result &= basic.numbersLower(res, 0, __name__, True)

    res = libc.string.strcmp(str2, str1)
    result &= basic.numbersLower(res, 0, __name__, True)
    res = libc.string.strcmp(str2, str2)
    result &= basic.numbersEquals(res, 0, __name__, True)
    res = libc.string.strcmp(str2, str3)
    result &= basic.numbersLower(res, 0, __name__, True)
    res = libc.string.strcmp(str2, str4)
    result &= basic.numbersLower(res, 0, __name__, True)

    res = libc.string.strcmp(str3, str1)
    result &= basic.numbersEquals(res, 0, __name__, True)
    res = libc.string.strcmp(str3, str2)
    result &= basic.numbersHigher(res, 0, __name__, True)
    res = libc.string.strcmp(str3, str3)
    result &= basic.numbersEquals(res, 0, __name__, True)
    res = libc.string.strcmp(str3, str4)
    result &= basic.numbersLower(res, 0, __name__, True)

    res = libc.string.strcmp(str4, str1)
    result &= basic.numbersHigher(res, 0, __name__, True)
    res = libc.string.strcmp(str4, str2)
    result &= basic.numbersHigher(res, 0, __name__, True)
    res = libc.string.strcmp(str4, str3)
    result &= basic.numbersHigher(res, 0, __name__, True)
    res = libc.string.strcmp(str4, str4)
    result &= basic.numbersEquals(res, 0, __name__, True)

    logger.log("Functional 1 done", __name__)
